package com.doc.controller;

import com.doc.bean.URLSAVE;
import com.doc.bean.User;
import com.doc.service.CategoryService;
import com.doc.test.MyUtil;
import com.doc.bean.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenwt
 */
@Api(value = "User控制器")
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    CategoryService categoryService;
    @ApiOperation(value = "根据用户id查询用户信息", httpMethod = "GET", produces = "application/json")
    @ApiResponse(code = 200, message = "success", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "queryUserById", method = RequestMethod.GET, produces = "application/json")
    public Result queryUserById(@ApiParam(name = "userId", required = true, value = "用户Id") @RequestParam("userId") int userId, HttpServletRequest request) {
        User user = new User(userId, "haoyifen", "321");
        Result result = new Result();
        result.setCode(0);
        result.setData(user);
        result.setMessage("success");
        return result;
    }

    @ApiOperation(value = "获取所有的url", httpMethod = "GET", produces = "application/json")
    @ApiResponse(code = 200, message = "success", response = URLSAVE.class)
    @ResponseBody
    @RequestMapping(value = "selectallurl", method = RequestMethod.GET, produces = "application/json")
    public List<URLSAVE> resultAllurl(@ApiParam(name = "userid", required = true, value = "用户Id") @RequestParam("userid") int userid){
        List<URLSAVE> cs = categoryService.selectallcontext();
        System.out.println(userid+"");
        return cs;
    }

}
